import { computed, ref } from 'vue';

import { defineStore } from 'pinia';

import { auto1688stor } from '#/store';

import { in1688ToDoudianStore } from '../modules';

export const use1688todyStroe = defineStore('use1688tody', () => {
  const in1688ToDoudian: any = in1688ToDoudianStore();
  const auto1688storTres = auto1688stor();
  const openStatus = ref(false);
  const showSelectBox = ref(false);
  const openDrawer = ref(false);
  const getInStoreBindShops: any = computed(() =>
    auto1688storTres.auto1688.bindShopList?.filter((item: any) => {
      item.label = item.shopName;
      item.value = item.shopId;
      return item.pType === 2;
    }),
  );

  function openFn(data: any) {
    // openStatus.value = true;
    // in1688ToDoudian.$reset();
    in1688ToDoudian.setSelectData(data);
    // console.log('data', data);

    // if (getInStoreBindShops.value?.length === 1) {
    //   // in1688ToDoudian.selectShop.values = [getInStoreBindShops.value[0].value];
    //   console.log('getInStoreBindShops.value[0]', getInStoreBindShops.value[0]);
    //   in1688ToDoudian.setselectShop([getInStoreBindShops.value[0]]);
    //   in1688ToDoudian.setSelectData(data);
    //   openSelectDeit();
    //   showSelectBox.value = false;
    //   return false;
    // }

    showSelectBox.value = true;
  }
  // function openSelectDeit() {
  //   if (in1688ToDoudian.selectShop.length === 0) {
  //     return message.error('请选择铺货店铺');
  //   }
  //   // in1688ToDoudian.setSelectData({
  //   //   selectGoods: props.selectItemList,
  //   // });
  //   openDrawer.value = true;
  //   showSelectBox.value = false;
  //   // console.log('openDrawer', openDrawer.value);
  // }
  function $reset() {
    openStatus.value = false;
  }
  return {
    $reset,
    openStatus,
    openFn,
    showSelectBox,
    openDrawer,
    getInStoreBindShops,
  };
});
